package com.lzxzjy.util;

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;

public final class MailCodeUtil {
    private MailCodeUtil() {}

    public static Session createSession() {

        //	账号信息
        final String username = "zhenxi.lu@foxmail.com";//	邮箱发送账号
        final String password = "urppnfbfsdcndfjf";//	邮箱授权码

        //	创建一个配置文件，并保存
        Properties props = new Properties();

        //	SMTP服务器连接信息
        props.put("mail.smtp.host", "smtp.qq.com");//	SMTP主机名

        props.put("mail.smtp.auth", "true");//	是否需要用户认证
        props.put("mail.smtp.starttls.enable", "true");//	启用TlS加密

        return Session.getInstance(props,new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                // TODO Auto-generated method stub
                return new PasswordAuthentication(username,password);
            }
        });
    }
}